package com.ff.discounts.component.freedetail

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.recyclerview.widget.GridLayoutManager
import com.ff.discounts.R
import com.ff.discounts.activity.BaseViewModelActivity
import com.ff.discounts.component.productdetail.BuyDialogFragment
import com.ff.discounts.component.productdetail.ProductDetailActivity
import com.ff.discounts.component.productdetail.RecommendAdapter
import com.ff.discounts.component.tab.home.HistoryData
import com.ff.discounts.databinding.ActivityFreeDetailBinding
import com.ff.discounts.fragment.BaseViewModelFragment
import com.ff.discounts.superui.decoration.GridDividerItemDecoration
import com.ff.discounts.superui.util.DensityUtil
import com.qmuiteam.qmui.util.QMUIStatusBarHelper

class FreeDetailActivity : BaseViewModelActivity<ActivityFreeDetailBinding>() {
    private lateinit var freeAdapter: FreeGoodsAdapter
    override fun initViews() {
        super.initViews()
        // 设置沉浸式状态栏
        QMUIStatusBarHelper.translucent(this)
        // 限时秒杀
        val itemDecoration = GridDividerItemDecoration(
            binding.skillList.context,
            DensityUtil.dip2px(binding.skillList.context, 5f).toInt()
        )
        binding.skillList.apply {
            layoutManager = GridLayoutManager(hostActivity,2)
            addItemDecoration(itemDecoration)
        }
        showDiscountDialog()

    }

    override fun initDatum() {
        super.initDatum()
        //  // 热门推荐适配器
        freeAdapter = FreeGoodsAdapter()
        binding.skillList.adapter = freeAdapter
        freeAdapter.submitList(FreeDetailActivity.historyDataList)
    }

    override fun initListeners() {
        super.initListeners()
        binding.back.setOnClickListener {
            finish()
        }

        binding.bottomBtnRight.setOnClickListener {
            showHotOneDialog()
        }

        // 点击立即购买按钮
        binding.bottomBtnLeft.setOnClickListener {
            showPayBottomDialog()
        }


    }

    /**
     * 显示购买dialog
     */
    private fun showDiscountDialog() {
        DiscountDialog.show(supportFragmentManager){

        }
    }

    /**
    * 立即购买底部按钮
    */
    private fun showPayBottomDialog() {
        PayBottomDialog.show(supportFragmentManager){

        }
    }


    private fun showHotOneDialog() {
        HotOneDialog.show(supportFragmentManager){

        }
    }

    companion object{

        private val historyDataList = mutableListOf<HistoryData>(
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集")

        )
        /**
         * 指示器标题
         */
        private val indicatorTitles = intArrayOf(
            R.string.product,
            R.string.evaluation,
            R.string.detail,
            R.string.recommend
        )
    }


}